package personal.study.bl;

import java.sql.Connection;
import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import personal.study.db.DBLogin;
import personal.study.form.LoginForm;
import personal.study.util.DBConnection;

public class BLLoginAction {

	private static Log log = LogFactory.getLog(BLLoginAction.class);
	
	public LoginForm findByPrimaryKey(String userCode) throws Exception{
		LoginForm loginForm = null;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBLogin dbLogin = new DBLogin();
			loginForm = dbLogin.findByPriaryKey(con, userCode);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return loginForm;
	}
	
	public Collection<LoginForm> queryResult(String conditions, int currentPage, int rowsPerPage) throws Exception{
		Collection<LoginForm> col = null;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBLogin dbLogin = new DBLogin();
			col = dbLogin.queryResult(con, conditions, currentPage, rowsPerPage);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		
		return col;
	}
	
	public int getCount(String conditions) throws Exception{
		int count = 0;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			count = new DBLogin().getCount(con, conditions);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return count;
	}
	public boolean insert(LoginForm loginform) throws Exception{
		boolean col = false;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBLogin dbLogin = new DBLogin();
			col = dbLogin.insert(con, loginform);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		
		return col;
	}
	public void delete(String UserCode) throws Exception{
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBLogin dbLogin = new DBLogin();
			dbLogin.delete(con, UserCode);
		}catch(Exception e){
			log.error(e.getMessage());
		}
	}
	public boolean update(LoginForm loginform) throws Exception{
        boolean result = false;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBLogin dbLogin = new DBLogin();
			result = dbLogin.update(con, loginform);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return result;
		}
	}
